package com.springboot.java.design.data_structure;

/**
 * @Author: TongRui乀
 * @Date: 2020-09-02 10:30
 * @description：
 */
public class BinaryTreeTest {

    public static void main(String[] args) {


    }

    /**
     *  求最大通路长度 也就是最大的左右子树高度和
     * @param head
     * @return
     */
    public static int maxHeightSum(TreeNode head){

        if(head == null){
            return 0;
        }

        return maxChildHeightSum(head.left) + maxChildHeightSum(head.right);
    }

    public static int maxChildHeightSum(TreeNode head){

        if(head == null){
            return 0;
        }

        int leftHeight = maxChildHeightSum(head.left);

        int rightHeight = maxChildHeightSum(head.right);

        return Math.max(leftHeight, rightHeight) + 1;
    }


}
